package com.xingkeduo.business.operation.domain;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.xingkeduo.business.operation.service.*;
import com.xingkeduo.pojo.dto.Hairstyle.*;
import com.xingkeduo.pojo.query.HairstyleQuery;
import com.xingkeduo.pojo.query.PictureQuery;
import com.xingkeduo.pojo.table.*;
import com.xingkeduo.tool.CheckDiffListUtils;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.pojo.enums.YesNoEnum;
import com.xingkeduo.util.pojo.exception.DataException;
import com.xingkeduo.util.tool.CommonUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;

import static com.xingkeduo.tool.OperaConstants.IMG_DIR_ADDRESS;
import static com.xingkeduo.tool.OperaConstants.OLD_IMG_DIR_ADDRESS;

/**
 * 商户domain
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class HairstyleDomain {

    @Autowired
    private HairstyleService hairstyleService;

    @Autowired
    private ServprodService servprodService;

    @Autowired
    private HairstyleTagsService hairstyleTagsService;

    @Autowired
    private PictureService pictureService;

    public SeeHairstyleDetailDTO getHairstyleInfoById(long id) throws Throwable {

        SeeHairstyleDetailDTO seeHairstyleDetailDTO = new SeeHairstyleDetailDTO();
        HairstyleTable hairstyleTable = hairstyleService.selectById(id);
        if(!CommonUtil.isEmpty(hairstyleTable)){
            BeanUtils.copyProperties(hairstyleTable,seeHairstyleDetailDTO);
        }
        //封面图片写入
        List<Map> coverDir = new ArrayList<>();
        if (!CommonUtil.isEmpty(hairstyleTable.getCover())) {
            List<PictureTable> pictureTables = pictureService.selectLists(new PictureQuery().setOssId(hairstyleTable.getCover()));
            for (PictureTable pictureTable : pictureTables) {
                if (!CommonUtil.isEmpty(pictureTable.getPicDir())) {
                    Map cover = new HashMap();
                    cover.put("id",hairstyleTable.getCover());
                    cover.put("coverDir",IMG_DIR_ADDRESS+pictureTable.getPicDir());
                    coverDir.add(cover);
                }
            }
            seeHairstyleDetailDTO.setCoverDetail(coverDir);
        }
        //立体图片写入
        ArrayList<Map> solidArray = new ArrayList<>();
        if (!CommonUtil.isEmpty(hairstyleTable.getPicIds())) {
            String[] PicIds = hairstyleTable.getPicIds().split(",");
            for (String picid : PicIds) {
                PictureTable pictureTable = pictureService.selectById(Long.valueOf(picid));
                Map solid = new HashMap();
                solid.put("id",picid);
                solid.put("solidDir",IMG_DIR_ADDRESS+pictureTable.getPicDir());
                solidArray.add(solid);
            }
            seeHairstyleDetailDTO.setSolidDetail(solidArray);
        }
        //发型解刨图写入
        ArrayList<Map> anatomyIdsArray = new ArrayList<>();
        if (!CommonUtil.isEmpty(hairstyleTable.getAnatomyIds())) {
            String[] anatomyIds = hairstyleTable.getAnatomyIds().split(",");
            for (String anatomyId : anatomyIds) {
                PictureTable pictureTable = pictureService.selectById(Long.valueOf(anatomyId));
                Map anatomy = Maps.newHashMap();
                anatomy.put("id",anatomyId);
                anatomy.put("anatomyDir",IMG_DIR_ADDRESS+pictureTable.getPicDir());
                anatomyIdsArray.add(anatomy);
            }
          seeHairstyleDetailDTO.setAnatomyDetail(anatomyIdsArray);
        }
        return seeHairstyleDetailDTO;
    }



    //创建
    @Transactional
    public int createHairstyle(HairstyleDTO hairstyleDTO) throws Throwable {
        if(!CommonUtil.isEmpty(hairstyleDTO.getName())){
            List<HairstyleTable> hairstyleTableList = hairstyleService.selectHairstyles(new HairstyleQuery().setNameRepeat(hairstyleDTO.getName()));
            if(!CommonUtil.isEmpty(hairstyleTableList)){
                throw new DataException(DataException.Type.DEFAULT, "发型名字已经存在");
            }
        }
        HairstyleTable hairstyleTable = new HairstyleTable();
        //封面图片
        ArrayList<String> coverImgTable = new ArrayList<>();
        List<HairstyleImgDTO> coverInfo = hairstyleDTO.getCoverImg();
        for (HairstyleImgDTO hairstyleImgDTO : coverInfo) {
            PictureTable pictureTable = new PictureTable();
            pictureTable.setOssId(hairstyleImgDTO.getOssId()).setPicDir(hairstyleImgDTO.getPicDir()).setPicType(2);
            int insert2 = pictureService.insert(pictureTable);
            coverImgTable.add(String.valueOf(pictureTable.getId()));
        }
        hairstyleTable.setCover(StringUtils.join(coverImgTable, ","));
        //360度图片
        ArrayList<String> picImg = new ArrayList<>();
        List<HairstyleImgDTO> picImgInfo = hairstyleDTO.getPicImg();
        for (HairstyleImgDTO hairstyleImgDTO : picImgInfo) {
            PictureTable pictureTable = new PictureTable();
            pictureTable.setOssId(hairstyleImgDTO.getOssId()).setPicDir(hairstyleImgDTO.getPicDir()).setPicType(3);
            int insert1 = pictureService.insert(pictureTable);
            picImg.add(String.valueOf(pictureTable.getId()));
        }
        hairstyleTable.setPicIds(StringUtils.join(picImg, ","));
        //发型解刨图
        ArrayList<String> anatomyImg = new ArrayList<>();
        List<HairstyleImgDTO> anatomyImgInfo = hairstyleDTO.getAnatomyImg();

        for (HairstyleImgDTO hairstyleImgDTO : anatomyImgInfo) {
            PictureTable pictureTable = new PictureTable();
            pictureTable.setOssId(hairstyleImgDTO.getOssId()).setPicDir(hairstyleImgDTO.getPicDir()).setPicType(4);
            int insert1 = pictureService.insert(pictureTable);
            anatomyImg.add(String.valueOf(pictureTable.getId()));
        }
        hairstyleTable.setAnatomyIds(StringUtils.join(anatomyImg, ","));
        BeanUtils.copyProperties(hairstyleDTO, hairstyleTable);
        int hairstyleId = hairstyleService.insert(hairstyleTable);
        return hairstyleId;
    }

    //修改
    public int modifyHairstyle(HairstyleDTO hairstyleDTO) throws Throwable {
        HairstyleTable hairstyleTable1 = hairstyleService.selectById(hairstyleDTO.getId());
        if(CommonUtil.isEmpty(hairstyleTable1)){
            throw new DataException(DataException.Type.DEFAULT, "发型ID不存在");
        }
        if(!CommonUtil.isEmpty(hairstyleDTO.getName())){
            if(!hairstyleTable1.getName().equals(hairstyleDTO.getName())){
                if(!CommonUtil.isEmpty(hairstyleDTO.getName())){
                    List<HairstyleTable> hairstyleTableList = hairstyleService.selectHairstyles(new HairstyleQuery().setNameRepeat(hairstyleDTO.getName()));
                    if(!CommonUtil.isEmpty(hairstyleTableList) && hairstyleTableList.size()>0){
                        throw new DataException(DataException.Type.DEFAULT, "发型名字已经存在");
                    }
                }
            }
        }
        HairstyleTable hairstyleTable = new HairstyleTable();
        BeanUtils.copyProperties(hairstyleDTO, hairstyleTable);
        //封面图片上传
        if(!CommonUtil.isEmpty(hairstyleTable1.getCover())){
            List<String> oldCoverImgOssId = new ArrayList<>();
            PictureTable oldCoverImgInfo = pictureService.selectById(Long.valueOf(hairstyleTable1.getCover()));
            oldCoverImgOssId.add(oldCoverImgInfo.getOssId());
        List<String> newCoverImgOssId = new ArrayList<>();
        List<HairstyleImgDTO> coverImg = hairstyleDTO.getCoverImg();
        for (HairstyleImgDTO coverImgDTO : coverImg) {
            newCoverImgOssId.add(coverImgDTO.getOssId());
        }
        ArrayList<String> coverImgId = new ArrayList<>();
        if(!CheckDiffListUtils.getDiffrent(oldCoverImgOssId,newCoverImgOssId)){
            for (HairstyleImgDTO coverImgDTO : coverImg) {
                PictureTable pictureTable = new PictureTable();
                pictureTable.setOssId(coverImgDTO.getOssId()).setPicDir(coverImgDTO.getPicDir()).setPicType(2);
                int insert = pictureService.insert(pictureTable);
                coverImgId.add(String.valueOf(pictureTable.getId()));
            }
            hairstyleTable.setCover(StringUtils.join(coverImgId, ","));
            //删除之前的图片
            PictureTable pictureTable1 = new PictureTable();
            pictureTable1.setId(Long.valueOf(hairstyleTable1.getCover()))
                    .setIsDelete(YesNoEnum.YES);
            pictureService.update(pictureTable1);
          }
        }else{
            List<HairstyleImgDTO> coverImg = hairstyleDTO.getCoverImg();
            ArrayList<String> coverImgId = new ArrayList<>();
            if(!CommonUtil.isEmpty(coverImg)){
                for (HairstyleImgDTO coverImgDTO : coverImg) {
                    PictureTable pictureTable = new PictureTable();
                    pictureTable.setOssId(coverImgDTO.getOssId()).setPicDir(coverImgDTO.getPicDir()).setPicType(2);
                    int insert = pictureService.insert(pictureTable);
                    coverImgId.add(String.valueOf(pictureTable.getId()));
                }
                hairstyleTable.setCover(StringUtils.join(coverImgId, ","));
            }
        }
        //360度图片上传
        if(!CommonUtil.isEmpty(hairstyleTable1.getPicIds())) {
            String[] picId = hairstyleTable1.getPicIds().split(",");
            //老的360图片
            List<String> oldPicImgOssId = new ArrayList<>();
            for (String ss : picId) {
                PictureTable getOldPicOssId = pictureService.selectById(Long.valueOf(ss));
                oldPicImgOssId.add(getOldPicOssId.getOssId());
            }
            //新的OssId
            List<String> newPicImgOssId = new ArrayList<>();
            //插入门店图片
            ArrayList<String> picImgId = new ArrayList<>();
            List<HairstyleImgDTO> picImgInfo = hairstyleDTO.getPicImg();
            for (HairstyleImgDTO picImg : picImgInfo) {
                newPicImgOssId.add(picImg.getOssId());
            }
            if (!CheckDiffListUtils.getDiffrent(oldPicImgOssId, newPicImgOssId)) {
                for (HairstyleImgDTO picImg : picImgInfo) {
                    PictureTable pictureTable = new PictureTable();
                    pictureTable.setOssId(picImg.getOssId()).setPicDir(picImg.getPicDir()).setPicType(3);
                    int insert = pictureService.insert(pictureTable);
                    picImgId.add(String.valueOf(pictureTable.getId()));
                }
                hairstyleTable.setPicIds(StringUtils.join(picImgId, ","));
                //删除之前的图片
                for (String s : picId) {
                    PictureTable pictureTable1 = new PictureTable();
                    pictureTable1.setId(Long.valueOf(s))
                            .setIsDelete(YesNoEnum.YES);
                    pictureService.update(pictureTable1);
                }
            }
        }else{
            //插入门店图片
            ArrayList<String> picImgId = new ArrayList<>();
            List<HairstyleImgDTO> picImgInfo = hairstyleDTO.getPicImg();
            if(!CommonUtil.isEmpty(picImgInfo)){
                for (HairstyleImgDTO picImg : picImgInfo) {
                    PictureTable pictureTable = new PictureTable();
                    pictureTable.setOssId(picImg.getOssId()).setPicDir(picImg.getPicDir()).setPicType(3);
                    int insert = pictureService.insert(pictureTable);
                    picImgId.add(String.valueOf(pictureTable.getId()));
                }
                hairstyleTable.setPicIds(StringUtils.join(picImgId, ","));
            }
        }

        //发型解刨图
        if(!CommonUtil.isEmpty(hairstyleTable1.getAnatomyIds())) {
            String[] AnatomyId = hairstyleTable1.getAnatomyIds().split(",");
            //老的解刨图
            List<String> oldAnatomyImgOssId = new ArrayList<>();
            for (String ss : AnatomyId) {
                PictureTable getOldPicOssId = pictureService.selectById(Long.valueOf(ss));
                oldAnatomyImgOssId.add(getOldPicOssId.getOssId());
            }

            //新的OssId
            List<String> newAnatomyImgOssId = new ArrayList<>();
            //插入门店图片
            ArrayList<String> AnatomyImgId = new ArrayList<>();
            List<HairstyleImgDTO> AnatomyImgInfo = hairstyleDTO.getAnatomyImg();
            for (HairstyleImgDTO AnatomyImg : AnatomyImgInfo) {
                newAnatomyImgOssId.add(AnatomyImg.getOssId());
            }
            if (!CheckDiffListUtils.getDiffrent(oldAnatomyImgOssId, newAnatomyImgOssId)) {
                for (HairstyleImgDTO picImg : AnatomyImgInfo) {
                    PictureTable pictureTable = new PictureTable();
                    pictureTable.setOssId(picImg.getOssId()).setPicDir(picImg.getPicDir()).setPicType(4);
                    int insert = pictureService.insert(pictureTable);
                    AnatomyImgId.add(String.valueOf(pictureTable.getId()));
                }
                hairstyleTable.setAnatomyIds(StringUtils.join(AnatomyImgId, ","));

                //删除之前的图片
                for (String s : AnatomyId) {
                    PictureTable pictureTable1 = new PictureTable();
                    pictureTable1.setId(Long.valueOf(s))
                            .setIsDelete(YesNoEnum.YES);
                    pictureService.update(pictureTable1);
                }
            }
        }else{
            //插入门店图片
            ArrayList<String> AnatomyImgId = new ArrayList<>();
            List<HairstyleImgDTO> AnatomyImgInfo = hairstyleDTO.getPicImg();
            if(!CommonUtil.isEmpty(AnatomyImgInfo)){
                for (HairstyleImgDTO picImg : AnatomyImgInfo) {
                    PictureTable pictureTable = new PictureTable();
                    pictureTable.setOssId(picImg.getOssId()).setPicDir(picImg.getPicDir()).setPicType(4);
                    int insert = pictureService.insert(pictureTable);
                    AnatomyImgId.add(String.valueOf(pictureTable.getId()));
                }
                hairstyleTable.setAnatomyIds(StringUtils.join(AnatomyImgId, ","));
            }
        }
        int update = hairstyleService.update(hairstyleTable);
        return update;
    }

    //删除
    public int delHairstyle(Long id) throws Throwable {
        HairstyleTable hairstyleTable = new HairstyleTable();
        hairstyleTable.setId(id);
        hairstyleTable.setIsDelete(YesNoEnum.YES);
        int delRes = hairstyleService.delete(hairstyleTable);
        if (delRes > 0) {
            return delRes;
        } else {
            throw new DataException(DataException.Type.FAIL, "删除失败");
        }
    }

    //获取列表
    public List<HairstyleTable> getHairstylelists(HairstyleQuery hairstyleQuery) throws Throwable {
        //查询已开启的
        List<HairstyleTable> hairstyleList = hairstyleService.selectHairstyles(hairstyleQuery);
        return hairstyleList;
    }

    //API
    public HairstyleDetailResponseDTO getHairstyleInfoApiById(long id) throws Throwable {
        if(CommonUtil.isEmpty(id)){
            throw new DataException(DataException.Type.DEFAULT, "发型ID不能为空!");
        }
        HairstyleTable hairstyleTable = hairstyleService.selectById(id);
        List<String> picList = new ArrayList<>();
        List<String> stringList = new ArrayList<>();
        List<String> faceList = new ArrayList<>();
        if (!CommonUtil.isEmpty(hairstyleTable.getStyleTagids())) {
            String[] styleIds = hairstyleTable.getStyleTagids().split(",");
            for (String styleId : styleIds) {
                HairstyleTagsTable hairstyleTagsTable = hairstyleTagsService.selectById(Long.valueOf(styleId));
                if (!CommonUtil.isEmpty(hairstyleTagsTable)) {
                    stringList.add(hairstyleTagsTable.getName());
                }
            }
        }
        if (!CommonUtil.isEmpty(hairstyleTable.getFaceTagids())) {
            String[] styleIds = hairstyleTable.getFaceTagids().split(",");
            for (String styleId : styleIds) {
                HairstyleTagsTable hairstyleTagsTable = hairstyleTagsService.selectById(Long.valueOf(styleId));
                if (!CommonUtil.isEmpty(hairstyleTagsTable)) {
                    faceList.add(hairstyleTagsTable.getName());
                }
            }
        }
        //360度
//        if (!CommonUtil.isEmpty(hairstyleTable.getPicIds())) {
//            String[] picIds = hairstyleTable.getPicIds().split(",");
//            for (String picId : picIds) {
//                PictureTable pictureTables = pictureService.selectById(Long.valueOf(picId));
//                if (!CommonUtil.isEmpty(pictureTables)) {
//                    picList.add(pictureTables.getPicDir());
//                }
//            }
//        }
        //360度图片，暂时写死
       for(int i=1;i<25;i++){
          String picIds = OLD_IMG_DIR_ADDRESS+"/imgs/"+id+"/"+i+".jpg";
           picList.add(picIds);
       }

        //发型解刨图
        List<String> anatomyImgList = new ArrayList<>();
//        if (!CommonUtil.isEmpty(hairstyleTable.getAnatomyIds())) {
//            String[] anatomyIds = hairstyleTable.getAnatomyIds().split(",");
//            for (String anatomyId : anatomyIds) {
//                PictureTable pictureTable1 = pictureService.selectById(Long.valueOf(anatomyId));
//                if (!CommonUtil.isEmpty(pictureTable1)) {
//                    anatomyImgList.add(pictureTable1.getPicDir());
//                }
//            }
//        }
        //发型解刨图暂时写死
        String anatomyId = OLD_IMG_DIR_ADDRESS+"/imgs/"+id+"/hair_details.jpg";
        anatomyImgList.add(anatomyId);
        //封面
//        PictureTable pictureTable = new PictureTable();
//        if (!CommonUtil.isEmpty(hairstyleTable.getCover())) {
////            pictureTable = pictureService.selectById(Long.valueOf(hairstyleTable.getCover()));
//
//        }
        //封面图片暂时写死
        String coverDir = OLD_IMG_DIR_ADDRESS+"/imgs/"+id+"/";
        HairstyleDetailResponseDTO build = HairstyleDetailResponseDTO.builder()
                .enmark(hairstyleTable.getEnmark())
                .id(id)
                .intro(hairstyleTable.getIntro())
                .name(hairstyleTable.getName())
                .sex(hairstyleTable.getSex())
                .title(hairstyleTable.getTitle())
                .cover(coverDir)
                .picIds(picList)
                .anatomyImg(anatomyImgList)
                .hairstyleTags(stringList)
                .faceTags(faceList)
                .likeNum(hairstyleTable.getLikeNum())
                .build();

        return build;
    }

    //获取API列表
    public List<HairstyleResponseDTO> getHairstyleApilists(HairstyleQuery hairstyleQuery) throws Throwable {
        //查询已开启的
        List<HairstyleTable> hairstyleList = hairstyleService.selectHairstyles(hairstyleQuery);
        List<HairstyleResponseDTO> hairstyleResponseDTOList = new ArrayList<>();

        if (hairstyleList != null) {
            for (HairstyleTable hairstyleTable : hairstyleList) {
                List<String> stringList = new ArrayList<>();
                if(hairstyleTable!= null &&!CommonUtil.isEmpty(hairstyleTable.getStyleTagids())){
                String[] styleIds = hairstyleTable.getStyleTagids().split(",");
                   for (String styleId : styleIds) {
                       HairstyleTagsTable hairstyleTagsTable = hairstyleTagsService.selectById(Long.valueOf(styleId));
                       if (!CommonUtil.isEmpty(hairstyleTagsTable)) {
                           stringList.add(hairstyleTagsTable.getName());
                       }
                   }
               }
                //360发型图
//                List<String> picList = new ArrayList<>();
//                if (!CommonUtil.isEmpty(hairstyleTable.getPicIds())) {
//                    String[] picIds = hairstyleTable.getPicIds().split(",");
//                    for (String picId : picIds) {
//                        PictureTable pictureTable = pictureService.selectById(Long.valueOf(picId));
//                        if (!CommonUtil.isEmpty(pictureTable)) {
//                            picList.add(pictureTable.getPicDir());
//                        }
//                    }
//                }

//                //发型解刨图
//                List<String> anatomyImgList = new ArrayList<>();
//                if (!CommonUtil.isEmpty(hairstyleTable.getAnatomyIds())) {
//                    String[] anatomyIds = hairstyleTable.getAnatomyIds().split(",");
//                    for (String anatomyId : anatomyIds) {
//                        PictureTable pictureTable1 = pictureService.selectById(Long.valueOf(anatomyId));
//                        if (!CommonUtil.isEmpty(pictureTable1)) {
//                            anatomyImgList.add(pictureTable1.getPicDir());
//                        }
//                    }
//                }
                //发型封面图
//                PictureTable pictureTable = new PictureTable();
//                if (!CommonUtil.isEmpty(hairstyleTable.getCover())) {
//                    pictureTable = pictureService.selectById(Long.valueOf(hairstyleTable.getCover()));
//                }

                //360度图片，暂时写死
                List<String> picList = new ArrayList<>();
                for(int i=1;i<25;i++){
                    String picid = OLD_IMG_DIR_ADDRESS+"/imgs/"+hairstyleTable.getId()+"/"+i+".jpg";
                    picList.add(picid);
                }
                String coverDir = OLD_IMG_DIR_ADDRESS+"/imgs/"+hairstyleTable.getId()+"/25.jpg";
                HairstyleResponseDTO build = HairstyleResponseDTO.builder()
                        .id(hairstyleTable.getId())
                        .enmark(hairstyleTable.getEnmark())
                        .title(hairstyleTable.getTitle())
                        .cover(coverDir)
                        .intro(hairstyleTable.getIntro())
                        .name(hairstyleTable.getName())
                        .picIds(picList)
//                        .anatomyImg(anatomyImgList)
                        .hairstyleTags(stringList)
                        .likeNum(hairstyleTable.getLikeNum())
                        .build();
                hairstyleResponseDTOList.add(build);

            }
        }

        return hairstyleResponseDTOList;
    }

    /**
     *chao老板那边的接口，选择发型师列表
     * @param hairstyleQuery
     * @return
     * @throws Throwable
     */

    //获取API列表
    public List<ChooseHairstyleDTO> getHairstyleApilist(HairstyleQuery hairstyleQuery) throws Throwable {
        //查询已开启的
        List<HairstyleTable> hairstyleList = hairstyleService.selectHairstyles(hairstyleQuery);
        List<ChooseHairstyleDTO> chooseHairstyleDTOList = new ArrayList<>();
        if (hairstyleList != null) {
            for (HairstyleTable hairstyleTable : hairstyleList) {
                //脸型标签
                List<String> stringList = new ArrayList<>();
                if(hairstyleTable!= null &&!CommonUtil.isEmpty(hairstyleTable.getFaceTagids())) {
                    String[] faceIds = hairstyleTable.getFaceTagids().split(",");
                    for (String faceId : faceIds) {
                        HairstyleTagsTable hairstyleTagsTable = hairstyleTagsService.selectById(Long.valueOf(faceId));
                        if (!CommonUtil.isEmpty(hairstyleTagsTable)) {
                            stringList.add(hairstyleTagsTable.getName());
                        }
                    }
                }
//                PictureTable pictureTable = new PictureTable();
//                if (!CommonUtil.isEmpty(hairstyleTable.getCover())) {
//                    pictureTable = pictureService.selectById(Long.valueOf(hairstyleTable.getCover()));
//                }
                String coverDir = OLD_IMG_DIR_ADDRESS+"/imgs/"+hairstyleTable.getId()+"/25.jpg";
                ChooseHairstyleDTO build = ChooseHairstyleDTO.builder()
                        .id(hairstyleTable.getId())
                        .name(hairstyleTable.getName())
                        .title(hairstyleTable.getTitle())
                        .faceList(stringList)
                        .cover(coverDir)
                        .build();
                chooseHairstyleDTOList.add(build);

            }
        }
        return chooseHairstyleDTOList;
    }
    //分页查询
    public Page<HairstyleTable> getHairstylePageList(HairstyleQuery hairstyleQuery) throws Throwable {
        Integer pageNo = hairstyleQuery.getPageNo();
        Integer pageSize = hairstyleQuery.getPageSize();
        Page<HairstyleTable> hairstyleTablePage = hairstyleService.selectPageLists(hairstyleQuery, pageNo, pageSize);
        List<HairstyleTable> hairstyleTabledtoList = hairstyleTablePage.getDtoList();
        if (!CommonUtil.isEmpty(hairstyleTabledtoList)) {

            for (HairstyleTable table : hairstyleTabledtoList) {

//                PictureTable pictureTable = new PictureTable();
//                if (!CommonUtil.isEmpty(table.getCover())) {
//                    pictureTable = pictureService.selectById(Long.valueOf(table.getCover()));
//                    if(!CommonUtil.isEmpty(pictureTable)){
//                        table.setCover(pictureTable.getPicDir());
//                    }
//                }
                String coverDir = OLD_IMG_DIR_ADDRESS+"/imgs/"+table.getId()+"/25.jpg";
                table.setCover(coverDir);
                if (!CommonUtil.isEmpty(table.getServprodIds())) {
                    ArrayList<String> servprodIdsList = new ArrayList<>();
                    String[] Ids = table.getServprodIds().split(",");
                    for (String id : Ids) {
                        ServprodTable servprodTable = servprodService.selectById(Long.valueOf(id));
                        servprodIdsList.add(servprodTable.getName());
                    }
                    table.setServprodIds(StringUtils.strip(servprodIdsList.toString(), "[]"));
                }

                if (!CommonUtil.isEmpty(table.getStyleTagids())) {
                    List<String> styletagList = new ArrayList<>();
                    String[] styleIds = table.getStyleTagids().split(",");
                    for (String styleId : styleIds) {
                        HairstyleTagsTable hairstyleTagsTable = hairstyleTagsService.selectById(Long.valueOf(styleId));
                        if (!CommonUtil.isEmpty(hairstyleTagsTable)) {
                            styletagList.add(hairstyleTagsTable.getName());
                        }
                    }
                    table.setStyleTagids(JSON.toJSONString(styletagList));
                }

                if(!CommonUtil.isEmpty(table.getTitle())){
                    table.setTitle(table.getTitle());
                }
            }
        }
        return hairstyleTablePage;
    }
}
